package main

import (
	"database/sql"
	"fmt"

	_ "github.com/ncruces/go-sqlite3/driver"
	_ "github.com/ncruces/go-sqlite3/embed"
)

func main() {
	db, err := sql.Open("sqlite3", "file:./db-access/example.db")
	defer db.Close()
	if err != nil {
		fmt.Println("Failed to open the database.")
	}

	query := "SELECT * FROM contacts"
	rows, err := db.Query(query)
	defer rows.Close()
	for rows.Next() {
		var contact_id int
		var first_name string
		var last_name string
		var email string
		var phone string

		err := rows.Scan(&contact_id, &first_name, &last_name, &email, &phone)
		if err != nil {
			fmt.Println("Failed to get items from the database.")
		} else {
			fmt.Printf("[Items]    %d %s %s %s %s\n", contact_id, first_name, last_name, email, phone)
		}
	}
}
